//
//  FarmDetailViewController.m
//  PeopleStreet
//
//  Created by 刘建峰 on 16/6/28.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "FarmDetailViewController.h"

@interface FarmDetailViewController ()<DYQBannerScrollViewDelegate>
/*****/
@property (strong,nonatomic) DYQBannerScrollView *bannerScrollView;//广告栏
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (nonatomic,strong)  NSMutableArray  *imageArray;
@property (weak, nonatomic) IBOutlet UILabel *farmTitle;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *farmDetail;
@property (weak, nonatomic) IBOutlet UIButton *collectButton;
@property(nonatomic,strong)NSString * phoneNumber;

@property (weak, nonatomic) IBOutlet UIImageView *farmImage;
@property (weak, nonatomic) IBOutlet UILabel *farmName;
@property (weak, nonatomic) IBOutlet UIImageView *farmLevel;


@end

@implementation FarmDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _imageArray = [NSMutableArray array];
    // Do any additional setup after loading the view.
    [self initViewLayout];
    [self getFarmDetail];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.scroView];
    //广告栏
    self.bannerScrollView = [[DYQBannerScrollView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 206), NO)];
    self.bannerScrollView.backgroundColor = [UIColor clearColor];
    self.bannerScrollView.pageControlPosition = PageControlPositionCenter;
    self.bannerScrollView.noDataPlaceholderImage = [UIImage imageNamed:@"cover_cy"];
    self.bannerScrollView.timeInterval = 3;
    self.bannerScrollView.pageControllerTintColor = [UIColor whiteColor];
    self.bannerScrollView.pageControllerCurrentColor = [UIColor orangeColor];
    [self.scroView insertSubview:self.bannerScrollView belowSubview:_collectButton];

    _scroView.contentSize = flexibleSize(CGSizeMake(0, 527), NO);
    
    _farmImage.layer.masksToBounds = YES;
    _farmImage.layer.cornerRadius = 13*VerticalRatio();
}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark  ==  收藏
- (IBAction)collectHandel:(id)sender {
}

#pragma mark  ==  拨号
- (IBAction)callHandel:(id)sender {
    [Common callPhone:_phoneNumber view:self.view];
}


#pragma mark === 获取供应详情
- (void)getFarmDetail{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:_farmId forKey:@"mmsuId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_queryMallMarketSupplyInfo withHttpType:@"POST" withTag:SX_SX_queryMallMarketSupplyInfo];
}


#pragma mark----DYQBannerScrollViewDelegate

-(void)bannerScrollView:(DYQBannerScrollView *)bannerScrollView didSelectItemAtIndex:(NSInteger)index
{
//    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"PersonCenterStoryboard" bundle:nil];
//    WebDetailInfoViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"WebDetailInfo"];
//    page.objectId = _bannerArray[index][@"appAdertUrl"];
//    page.titleStr = @"详情";
//    page.meType = @"4";
//    [self.navigationController  pushViewController:page animated:YES];
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==SX_SX_queryMallMarketSupplyInfo) {
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            
            NSDictionary * dic= database[@"result"][@"supply"];
            
            [_imageArray addObject:[Common stringFromData:dic[@"mmsuImageUrl"]]];
            _bannerScrollView.imageUrls = _imageArray;
            _bannerScrollView.delegate = self;
            
            _farmTitle.text = [NSString stringWithFormat:@"%@",dic[@"mmsuName"]];
            _numberLabel.text = [NSString stringWithFormat:@"%@%@",dic[@"mmsuNum"],dic[@"mmsuLabel"]];
            _timeLabel.text = [NSString stringWithFormat:@"%@",dic[@"mmsuCreateTime"]];
            
            _farmDetail.frame = flexibleFrame(CGRectMake(14, 320, 296, 32), NO);
            _farmDetail.numberOfLines = 0;
            _farmDetail.text = [NSString stringWithFormat:@"%@",dic[@"mmsuContent"]];
            [_farmDetail sizeToFit];
            
            _phoneNumber = [NSString stringWithFormat:@"%@",dic[@"mmsuPhone"]];
            
            if (![dic[@"memberUrl"] isEqual:[NSNull null]]) {
            [_farmImage sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@",dic[@"memberUrl"]]]];
            }
            
            
            if (![dic[@"memberNickName"] isEqual:[NSNull null]]) {
                _farmName.text = [NSString stringWithFormat:@"%@",dic[@"memberNickName"]];
            }else{
                _farmName.text = [NSString stringWithFormat:@"%@",dic[@"memberLoginName"]];
            }
            
            [_farmName sizeToFit];
            _farmLevel.frame = CGRectMake(CGRectGetMaxX(_farmName.frame)+5, CGRectGetMinY(_farmLevel.frame), CGRectGetWidth(_farmLevel.frame), CGRectGetHeight(_farmLevel.frame));
            [_farmLevel sd_setImageWithURL:[NSURL URLWithString:[Common stringFromData:dic[@"memberLevelStr"]]]];
            
            if ([NSString stringWithFormat:@"%@",dic[@"mmsuCreateTime"] ].length>0) {
                
                _timeLabel.text = [Common updateTimeForData:[NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"] ]];
            }
            
            
        }
    }
    
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
        //
        [self dismissWaitDialog];
        
        
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
